package com.lrl.security.wiremock;

import com.github.tomakehurst.wiremock.client.WireMock;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;

/**
 * @author LRL
 */
public class WiremockServer {

    public static void main(String[] args) throws IOException {
        WireMock.configureFor(9520);
        WireMock.removeAllMappings();

        mock("/order/1","01");

        mock("/order/2","02");
    }
    private static void mock(String url, String file) throws IOException {
        ClassPathResource resource = new ClassPathResource("resources/wiremock/" +file+ ".txt");
        String content = StringUtils.join(FileUtils.readLines(resource.getFile(), "UTF-8").toArray(), "\n");
        WireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo(url)).willReturn(WireMock.aResponse().withBody(content).withStatus(200)));
    }
}
